var util = require('../../../utils/util.js');
var app = getApp()
var that;
Page({
  data: {
    postsList: [], //总的活动
    currentPage: 0, //要跳过查询的页数
    limitPage: 3,//首先显示3条数据（之后加载时都增加3条数据，直到再次加载不够3条）
    isEmpty: false, //当前查询出来的数据是否为空
    totalCount: 0, //总活动数量
    endPage: 0, //最后一页加载多少条
    totalPage: 0, //总页数
  },

  onLoad() {
    var self = this;
    var userId = wx.getStorageSync('user_id');
    var molist = new Array();
    wx.request({
      url: app.globalData.hostName + '/microappointment/user/allMyPublished?userId=' + userId,
      success: function (res) {
        var results = res.data.data;
        for (var i = 0; i < results.length; i++) {
          // var unixCreateTimestamp = new Date(results[i].createTime).toDateString();
          // var unixExpireTimestamp = new Date(results[i].expireTime).toDateString();
          var tempPicArray = new Array();
          if (results[i].pictureList.length > 0) {
            tempPicArray = results[i].pictureList;
          } else {
            tempPicArray = [{ pictureUrl: "https://www.daliandaxue.cn/img/not_upload.jpg" }];
          }
          var siglePic = tempPicArray[0];
          var jsonA = {
            "publisherPic": results[i].publisherPic || "/image/1.jpg",
            "publisherName": results[i].publisherName || '',
            "createTime": util.getDateDiff(results[i].createTime),
            "title": results[i].title || '',
            "actPic": siglePic.pictureUrl || '',
            "endtime": util.getDateDiff2(results[i].expireTime),
            "id": results[i].id || '',
            "publisherId": results[i].id || '',
            "address": results[i].location || ''
          }
          molist.push(jsonA);
          console.log("molist", molist);
        }
        self.setData({
          postsList: molist
        })
        //self.onSetData(molist, self.data.currentPage);
        //self.fetchPostsData(self.data); //加载首页信息
      },
      error: function (error) {
        console.log(error)
      }
    })
  },

  //数据存储
  onSetData: function (data) {
    let page = this.data.currentPage + 1;
    //设置数据
    data = data || [];
    this.setData({
      postsList: page === 1 || page === undefined ? data : this.data.postsList.concat(data),
    });
  },

  //获取首页列表文章
  fetchPostsData: function (data, endpage) {

  },

  onShow: function () {

  },

  // 点击活动进入活动详情页面
  click_activity: function (e) {
    console.log("debug e.currentTarget.id", e.currentTarget.dataset.id);
    wx.navigateTo({
      //url: "/pages/goods-details/index?id=" + e.currentTarget.dataset.id
      url: "/pages/detail/detail?id=" + e.currentTarget.dataset.id
    })
  },

})
